﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Values.xaml" />
    </ResourceDictionary.MergedDictionaries>


    <!--  MenuScrollViewer  -->
    <!--
            <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}"
            TargetType="{x:Type ScrollViewer}">
            <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
            <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="Template">
            <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
            
            <Grid >
            <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <Rectangle x:Name="bg"
            Grid.RowSpan="3"
            Fill="{StaticResource WindowBackgroundBrush}"
            Stroke="{StaticResource PressedBrush}"
            RadiusY="{StaticResource Radius}"
            RadiusX="{StaticResource Radius}"/>
            
            <ScrollContentPresenter Margin="{TemplateBinding Padding}" Grid.Row="1"/>
            
            <RepeatButton CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
            Command="{x:Static ScrollBar.LineUpCommand}"
            Focusable="false"
            Background="{StaticResource WindowBackgroundBrush}"
            BorderBrush="{x:Null}"
            Foreground="{StaticResource WindowForegroundBrush}">
            <RepeatButton.Visibility>
            <MultiBinding ConverterParameter="0"
            Converter="{StaticResource MenuScrollingVisibilityConverter}"
            FallbackValue="Visibility.Collapsed">
            <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
            </MultiBinding>
            </RepeatButton.Visibility>
            
            <Path Data="{StaticResource UpArrow}"
            Fill="{StaticResource WindowForegroundBrush}"/>
            
            </RepeatButton>
            
            <RepeatButton CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
            Command="{x:Static ScrollBar.LineDownCommand}"
            Focusable="false"
            Grid.Row="2"
            BorderBrush="{x:Null}"
            Background="{StaticResource WindowBackgroundBrush}"
            Foreground="{StaticResource WindowForegroundBrush}">
            <RepeatButton.Visibility>
            <MultiBinding ConverterParameter="100"
            Converter="{StaticResource MenuScrollingVisibilityConverter}"
            FallbackValue="Visibility.Collapsed">
            <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
            <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
            </MultiBinding>
            </RepeatButton.Visibility>
            
            <Path Data="{StaticResource DownArrow}"
            Fill="{StaticResource WindowForegroundBrush}"/>
            
            </RepeatButton>
            
            </Grid>
            </ControlTemplate>
            </Setter.Value>
            </Setter>
            </Style>
        -->

    <!--  MenuScrollButton  -->
    <!--
            <Style x:Key="MenuScrollButton" TargetType="{x:Type RepeatButton}">
            <Setter Property="ClickMode" Value="Hover"/>
            <Setter Property="MinWidth" Value="0"/>
            <Setter Property="MinHeight" Value="0"/>
            <Setter Property="Template">
            <Setter.Value>
            <ControlTemplate TargetType="{x:Type RepeatButton}">
            <DockPanel Background="Transparent" SnapsToDevicePixels="true">
            <Rectangle x:Name="R1" DockPanel.Dock="Right" Fill="Transparent" Width="1"/>
            <Rectangle x:Name="B1" DockPanel.Dock="Bottom" Fill="Transparent" Height="1"/>
            <Rectangle x:Name="L1" DockPanel.Dock="Left" Fill="Transparent" Width="1"/>
            <Rectangle x:Name="T1" DockPanel.Dock="Top" Fill="Transparent" Height="1"/>
            <ContentPresenter x:Name="ContentContainer"
            HorizontalAlignment="Center"
            Margin="2,2,2,2"
            VerticalAlignment="Center"/>
            </DockPanel>
            <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="true">
            <Setter Property="Fill"
            TargetName="R1"
            Value="{StaticResource PressedBrush}"/>
            <Setter Property="Fill"
            TargetName="B1"
            Value="{StaticResource PressedBrush}"/>
            <Setter Property="Fill"
            TargetName="L1"
            Value="{StaticResource PressedBrush}"/>
            <Setter Property="Fill"
            TargetName="T1"
            Value="{StaticResource PressedBrush}"/>
            <Setter Property="Margin"
            TargetName="ContentContainer" Value="3,3,1,1"/>
            </Trigger>
            </ControlTemplate.Triggers>
            </ControlTemplate>
            </Setter.Value>
            </Setter>
            </Style>
        -->

    <!--  TopLevelHeaderTemplate  -->
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Rectangle x:Name="bg"
                       Grid.RowSpan="2"
                       Fill="{TemplateBinding Background}" />
            <ContentPresenter x:Name="Icon"
                              ContentSource="Icon" />
            <ContentPresenter x:Name="contentPresenter"
                              Grid.Row="1"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center"
                              ContentSource="Header"
                              RecognizesAccessKey="True" />

            <Popup x:Name="PART_Popup"
                   Grid.RowSpan="2"
                   AllowsTransparency="true"
                   Focusable="false"
                   IsOpen="{Binding IsSubmenuOpen,
                                        RelativeSource={RelativeSource TemplatedParent}}"
                   Placement="Bottom"
                   PopupAnimation="{StaticResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   VerticalOffset="1">

                <ContentControl x:Name="SubMenuBorder"
                                IsTabStop="false"
                                Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent,
                                                                                     TypeInTargetAssembly={x:Type FrameworkElement}}}">

                    <ScrollViewer x:Name="SubMenuScrollViewer"
                                  CanContentScroll="true"
                                  Style="{StaticResource {ComponentResourceKey ResourceId=MenuScrollViewer,
                                                                                   TypeInTargetAssembly={x:Type FrameworkElement}}}">

                        <Grid RenderOptions.ClearTypeHint="Enabled">

                            <Rectangle x:Name="rectangle"
                                       Width="{Binding ActualWidth,
                                                           ElementName=SubMenuBorder}"
                                       Height="{Binding ActualHeight,
                                                            ElementName=SubMenuBorder}"
                                       Fill="{StaticResource ResourceKey=ViewBackgroundBrush}" />

                            <ItemsPresenter x:Name="ItemsPresenter"
                                            Margin="1"
                                            Grid.IsSharedSizeScope="true"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            KeyboardNavigation.TabNavigation="Cycle" />

                        </Grid>

                    </ScrollViewer>

                </ContentControl>

            </Popup>

        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation"
                     Value="true">
                <Setter TargetName="PART_Popup"
                        Property="PopupAnimation"
                        Value="None" />
            </Trigger>
            <Trigger Property="Icon"
                     Value="{x:Null}">
                <Setter TargetName="Icon"
                        Property="Visibility"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="true">
                <Setter Property="BorderBrush"
                        Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver"
                     Value="true">
                <Setter Property="Background"
                        Value="{StaticResource MouseOverBrush}" />
            </Trigger>
            <Trigger Property="IsPressed"
                     Value="true">
                <Setter Property="Background"
                        Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsSubmenuOpen"
                     Value="true">
                <Setter Property="Foreground"
                        Value="{StaticResource PressedForegroundBrush}" />
                <Setter Property="Background"
                        Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <!--  TopLevelItemTemplate  -->
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">

        <Border x:Name="bg"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding Background}"
                BorderThickness="2">
            <StackPanel>

                <ContentPresenter x:Name="Icon"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch"
                                  ContentSource="Icon" />

                <ContentPresenter x:Name="contentPresenter"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True" />
            </StackPanel>
        </Border>

        <ControlTemplate.Triggers>
            <Trigger Property="Icon"
                     Value="{x:Null}">
                <Setter TargetName="Icon"
                        Property="Visibility"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="true">
                <Setter TargetName="bg"
                        Property="BorderBrush"
                        Value="{StaticResource ListViewItemPressedBrush}" />
            </Trigger>
            <Trigger Property="IsMouseOver"
                     Value="true">
                <Setter Property="Background"
                        Value="{StaticResource MouseOverBrush}" />
            </Trigger>
            <Trigger Property="IsPressed"
                     Value="true">
                <Setter Property="Background"
                        Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{StaticResource DisabledForegroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <!--  SubmenuContent  -->
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}"
                     TargetType="{x:Type ContentControl}">

        <Grid>
            <ContentPresenter Grid.ColumnSpan="2" />
        </Grid>

    </ControlTemplate>

    <!--  SubmenuHeaderTemplate  -->
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">

        <Grid MinHeight="24">

            <Rectangle x:Name="bg"
                       Fill="Transparent" />

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      MinWidth="24"
                                      SharedSizeGroup="MenuItemIconColumnGroup" />
                    <ColumnDefinition Width="4" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="37" />
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="MenuItemIGTColumnGroup" />
                    <ColumnDefinition Width="17" />
                </Grid.ColumnDefinitions>

                <ContentPresenter x:Name="Icon"
                                  Margin="1"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  ContentSource="Icon" />

                <StackPanel Grid.Column="2"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">

                    <ContentPresenter Margin="{TemplateBinding Padding}"
                                      VerticalAlignment="Center"
                                      ContentSource="Header"
                                      RecognizesAccessKey="True" />

                    <Path x:Name="Glyph"
                          Width="9"
                          Height="11"
                          Margin="6 0 0 0"
                          VerticalAlignment="Center"
                          Data="{StaticResource Checkmark}"
                          Fill="{TemplateBinding Foreground}"
                          FlowDirection="LeftToRight"
                          Visibility="Collapsed" />

                </StackPanel>

                <TextBlock Grid.Column="4"
                           Margin="{TemplateBinding Padding}"
                           VerticalAlignment="Center"
                           Text="{TemplateBinding InputGestureText}"
                           Visibility="Collapsed" />

                <Path Grid.Column="5"
                      Margin="4,0,0,0"
                      VerticalAlignment="Center"
                      Data="{StaticResource RightArrow}"
                      Fill="{TemplateBinding Foreground}" />

            </Grid>

            <Popup x:Name="PART_Popup"
                   AllowsTransparency="true"
                   Focusable="false"
                   HorizontalOffset="3"
                   IsOpen="{Binding IsSubmenuOpen,
                                        RelativeSource={RelativeSource TemplatedParent}}"
                   Placement="Right"
                   PopupAnimation="{StaticResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   VerticalOffset="-2">

                <ContentControl x:Name="SubMenuBorder"
                                IsTabStop="false"
                                Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent,
                                                                                     TypeInTargetAssembly={x:Type FrameworkElement}}}">

                    <ScrollViewer x:Name="SubMenuScrollViewer"
                                  CanContentScroll="true"
                                  Style="{StaticResource {ComponentResourceKey ResourceId=MenuScrollViewer,
                                                                                   TypeInTargetAssembly={x:Type FrameworkElement}}}">

                        <Grid RenderOptions.ClearTypeHint="Enabled">

                            <Rectangle x:Name="rectangle"
                                       Width="{Binding ActualWidth,
                                                           ElementName=SubMenuBorder}"
                                       Height="{Binding ActualHeight,
                                                            ElementName=SubMenuBorder}"
                                       Fill="{StaticResource WindowBackgroundBrush}" />

                            <ItemsPresenter x:Name="ItemsPresenter"
                                            Margin="1"
                                            Grid.IsSharedSizeScope="true"
                                            KeyboardNavigation.DirectionalNavigation="Cycle"
                                            KeyboardNavigation.TabNavigation="Cycle" />

                        </Grid>

                    </ScrollViewer>

                </ContentControl>

            </Popup>

        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsSuspendingPopupAnimation"
                     Value="true">
                <Setter TargetName="PART_Popup"
                        Property="PopupAnimation"
                        Value="None" />
            </Trigger>
            <Trigger Property="Icon"
                     Value="{x:Null}">
                <Setter TargetName="Icon"
                        Property="Visibility"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="true">
                <Setter TargetName="Glyph"
                        Property="Visibility"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{StaticResource ViewForegroundBrush}" />
                <Setter Property="BorderBrush"
                        Value="{StaticResource ViewForegroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <!--  SubmenuItemTemplate  -->
    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}"
                     TargetType="{x:Type MenuItem}">

        <Grid MinHeight="42">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"
                                  MinWidth="42"
                                  SharedSizeGroup="MenuItemIconColumnGroup" />
                <ColumnDefinition Width="4" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="37" />
                <ColumnDefinition Width="Auto"
                                  SharedSizeGroup="MenuItemIGTColumnGroup" />
                <ColumnDefinition Width="17" />
            </Grid.ColumnDefinitions>

            <Rectangle x:Name="bg"
                       Grid.ColumnSpan="6"
                       Fill="{TemplateBinding Background}" />

            <ContentPresenter x:Name="Icon"
                              Margin="1"
                              ContentSource="Icon" />

            <StackPanel Grid.Column="2"
                        VerticalAlignment="Center"
                        Orientation="Horizontal">

                <ContentPresenter Margin="{TemplateBinding Padding}"
                                  VerticalAlignment="Center"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True" />

                <Path x:Name="Glyph"
                      Width="9"
                      Height="11"
                      Margin="6 0 0 0"
                      VerticalAlignment="Center"
                      Data="{StaticResource Checkmark}"
                      Fill="{TemplateBinding Foreground}"
                      FlowDirection="LeftToRight"
                      Visibility="Collapsed" />

            </StackPanel>

            <TextBlock Grid.Column="4"
                       Margin="{TemplateBinding Padding}"
                       VerticalAlignment="Center"
                       Text="{TemplateBinding InputGestureText}" />

        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="Icon"
                     Value="{x:Null}">
                <Setter TargetName="Icon"
                        Property="Visibility"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="true">
                <Setter TargetName="Glyph"
                        Property="Visibility"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="IsHighlighted"
                     Value="true">
                <Setter Property="Background"
                        Value="{StaticResource MouseOverBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{StaticResource ViewForegroundBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <!--  Menuitem  -->
    <Style TargetType="{x:Type MenuItem}">
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="HorizontalContentAlignment"
                Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="VerticalContentAlignment"
                Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="ScrollViewer.PanningMode"
                Value="Both" />
        <Setter Property="Stylus.IsFlicksEnabled"
                Value="False" />
        <Setter Property="Margin"
                Value="1" />
        <Setter Property="Template"
                Value="{StaticResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />

        <Style.Triggers>
            <Trigger Property="Role"
                     Value="TopLevelHeader">
                <Setter Property="Padding"
                        Value="7,2,8,3" />
                <Setter Property="Template"
                        Value="{StaticResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role"
                     Value="TopLevelItem">
                <Setter Property="Padding"
                        Value="7,2,8,3" />
                <Setter Property="Foreground"
                        Value="{StaticResource ViewForegroundBrush}" />
                <Setter Property="Template"
                        Value="{StaticResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role"
                     Value="SubmenuHeader">
                <Setter Property="Padding"
                        Value="2,3,2,3" />
                <Setter Property="Foreground"
                        Value="{StaticResource ViewForegroundBrush}" />
                <Setter Property="Template"
                        Value="{StaticResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
            </Trigger>
            <Trigger Property="Role"
                     Value="SubmenuItem">
                <Setter Property="Padding"
                        Value="2 3" />
                <Setter Property="Foreground"
                        Value="{StaticResource WindowForegroundBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{StaticResource DisabledBrush}" />
            </Trigger>
        </Style.Triggers>

    </Style>

    <!--  SeparatorTemplate  -->
    <ControlTemplate x:Key="SeparatorTemplate"
                     TargetType="{x:Type Separator}">
        <Rectangle Height="1"
                   Fill="{StaticResource PressedBrush}" />
    </ControlTemplate>

    <!--  Separator  -->
    <Style TargetType="{x:Type Separator}">
        <Setter Property="Height"
                Value="1" />
        <Setter Property="Margin"
                Value="0 2" />
        <Setter Property="Template"
                Value="{StaticResource SeparatorTemplate}" />
    </Style>

    <!--  Menuitemseparator  -->
    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}"
           TargetType="{x:Type Separator}">
        <Setter Property="Height"
                Value="1" />
        <Setter Property="Margin"
                Value="30 4 0 4" />
        <Setter Property="Template"
                Value="{StaticResource SeparatorTemplate}" />
    </Style>

</ResourceDictionary>